

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.HikCdcVideoMonitor;
import com.loong.loong.hik.service.HikCdcVideoMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 疾控视频监控
 *
 * @author jinyiang
 * @date 2023-04-26 16:13:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/hikcdcvideomonitor" )
@Api(value = "hikcdcvideomonitor", tags = "疾控视频监控管理")
public class HikCdcVideoMonitorController {

    private final  HikCdcVideoMonitorService hikCdcVideoMonitorService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param hikCdcVideoMonitor 疾控视频监控
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_view')" )
    public R getHikCdcVideoMonitorPage(Page page, HikCdcVideoMonitor hikCdcVideoMonitor) {
		return R.ok(hikCdcVideoMonitorService.page(page,
				Wrappers.query(hikCdcVideoMonitor).lambda()
						.like(StringUtils.isNotEmpty(hikCdcVideoMonitor.getLikeName()), HikCdcVideoMonitor::getLocation,hikCdcVideoMonitor.getLikeName())
						.between(StringUtils.isNotEmpty(hikCdcVideoMonitor.getStartTime())&&StringUtils.isNotEmpty(hikCdcVideoMonitor.getEndTime()),HikCdcVideoMonitor::getCreateTime,hikCdcVideoMonitor.getStartTime(),hikCdcVideoMonitor.getEndTime())));

    }


    /**
     * 通过id查询疾控视频监控
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(hikCdcVideoMonitorService.getById(id));
    }

    /**
     * 新增疾控视频监控
     * @param hikCdcVideoMonitor 疾控视频监控
     * @return R
     */
    @ApiOperation(value = "新增疾控视频监控", notes = "新增疾控视频监控")
    @SysLog("新增疾控视频监控" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_add')" )
    public R save(@RequestBody HikCdcVideoMonitor hikCdcVideoMonitor) {
        return R.ok(hikCdcVideoMonitorService.save(hikCdcVideoMonitor));
    }

    /**
     * 修改疾控视频监控
     * @param hikCdcVideoMonitor 疾控视频监控
     * @return R
     */
    @ApiOperation(value = "修改疾控视频监控", notes = "修改疾控视频监控")
    @SysLog("修改疾控视频监控" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_edit')" )
    public R updateById(@RequestBody HikCdcVideoMonitor hikCdcVideoMonitor) {
        return R.ok(hikCdcVideoMonitorService.updateById(hikCdcVideoMonitor));
    }

    /**
     * 通过id删除疾控视频监控
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除疾控视频监控", notes = "通过id删除疾控视频监控")
    @SysLog("通过id删除疾控视频监控" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(hikCdcVideoMonitorService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param hikCdcVideoMonitor 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_hikcdcvideomonitor_export')" )
    public List<HikCdcVideoMonitor> export(HikCdcVideoMonitor hikCdcVideoMonitor) {
        return hikCdcVideoMonitorService.list(Wrappers.query(hikCdcVideoMonitor));
    }
    /**
	 * 根据indexCode更新rtsp视频地址
     * @return
     */
    @PostMapping("/updateUrl")
    public R updateUrl(HikCdcVideoMonitor hikCdcVideoMonitor) {

        return hikCdcVideoMonitorService.updateUrl(hikCdcVideoMonitor);
    }
}
